package com.lin.filegraph.utils.filedg;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:30
 */

public enum CouplingType {
    //	强依赖类型计算依赖强度乘以3
    Inheritance, // 继承依赖
    Implements, // 实现依赖
    DeclareToDefine, // 声明-定义依赖
    Combination, // 组合依赖
    Other_Association, // 其他关联
    Call, // 函数调用依赖
    Instantiation, // 实例化依赖
    Parameter, // 参数类型依赖
    Return, // 返回值类型依赖
    DeclarationType, // 声明类型依赖
    Include, // include关键字依赖
    Import;// import关键字依赖
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		String str = "0,1,2,3,4,5,6,7,8,9,0,1";
//		System.out.println(CouplingType.getMapByStr(str));
//		System.out.println(CouplingType.getStrByMap(getMapByStr(str)));
//		System.out.println(getMapByStr(str).containsKey(Inheritance));
//
//	}

    // public static String getStrByList(Set<CouplingType> couplingTypes) {
    // StringBuilder sb = new StringBuilder();
    // for(CouplingType type:CouplingType.values()) {
    // if(couplingTypes.contains(type)) {
    // sb.append("1");
    // } else {
    // sb.append("0");
    // }
    // }
    // return sb.toString();
    // }
    // public static Set<CouplingType> getListByStr(String str) {
    // Set<CouplingType> couplingTypes = new HashSet<>();
    // CouplingType[] allTypes = CouplingType.values();
    // char[] arr = str.toCharArray();
    // for(int i = 0; i < arr.length; i ++) {
    // if(arr[i] == '1') {
    // couplingTypes.add(allTypes[i]);
    // }
    // }
    // return couplingTypes;
    // }

    public static String getStrByMap(Map<CouplingType, Integer> mapOfCouplingTypes) {
        StringBuilder sb = new StringBuilder();
        for (CouplingType type : CouplingType.values()) {
            if (mapOfCouplingTypes.containsKey(type)) {
                sb.append("" + mapOfCouplingTypes.get(type) + ",");
            } else {
                sb.append("0,");
            }
        }
        return sb.toString().substring(0, sb.length() - 1);
    }

    public static Map<CouplingType, Integer> getMapByStr(String str) {
        Map<CouplingType, Integer> mapOfCouplingTypes = new HashMap<>();
        CouplingType[] allTypes = CouplingType.values();
        String[] arr = str.split(",");
        for (int i = 0; i < arr.length; i++) {
            if (!"0".equals(arr[i])) {
                int count = Integer.parseInt(arr[i]);
                mapOfCouplingTypes.put(allTypes[i], count);
            }
        }
        return mapOfCouplingTypes;
    }

    // by suxiaowei
    public static String print(Set<CouplingType> couplingTypes) {
        StringBuilder sb = new StringBuilder();
        for (CouplingType type : CouplingType.values()) {
            if (couplingTypes.contains(type)) {
                sb.append(type);
                sb.append("/");
            }
        }
        sb.delete(sb.length() - 2, sb.length());
        return sb.toString();
    }

    public static Set<String> getListByStrs(String str) {
        Set<String> couplingTypes = new LinkedHashSet<>();
        CouplingType[] allTypes = CouplingType.values();
        String[] arr = str.split(",");
        for (int i = 0; i < arr.length; i++) {
            if (!arr[i].equals("0")) {
                couplingTypes.add(allTypes[i] + ":" + arr[i]);
            }
        }
        return couplingTypes;
    }

    public static String prints(Set<String> couplingTypes) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (String type : couplingTypes) {
            if (!isFirst)
                sb.append("</Br>");
            sb.append(type);
            isFirst = false;
        }
        // sb.delete(sb.length()-2,sb.length());
        return sb.toString();
    }
    public static CouplingType string_to_enum(String type){
        if(type.equals("DeclarationType")){
            return CouplingType.DeclarationType;
        }else if(type.equals("Return")){
            return CouplingType.Return;
        }else if(type.equals("Call")){
            return CouplingType.Call;
        }else if(type.equals("Combination")){
            return CouplingType.Combination;
        }else if(type.equals("DeclareToDefine")){
            return CouplingType.DeclareToDefine;
        }else if(type.equals("Implements")){
            return CouplingType.Implements;
        }else if(type.equals("Import")){
            return CouplingType.Import;
        }else if(type.equals("Inheritance")){
            return CouplingType.Inheritance;
        }else if(type.equals("Instantiation")){
            return CouplingType.Instantiation;
        }else if(type.equals("Parameter")){
            return CouplingType.Parameter;
        }else{
            return CouplingType.Other_Association;
        }
    }
}
